/**
 * Created by Administrator on 2017/8/24 0024.
 */

$(function () {
    $(".login-middle form input").focus(function () {
        $("#login-error").css("display","none");
    });
    // 登录发送请求
    function login() {
        var logPhoneOK = $('#logPhone').val();//账号
        var logPasswordOK = $('#logPassword').val();//密码
        $.ajax({
            url:BaseUrl +"/api/login",
            type:"post",
            data:"account="+logPhoneOK+"&password="+logPasswordOK,
            success:function(response){
                if (response.code == 0){//成功是 0
                    localStorage.setItem("token",response.token);
                    localStorage.setItem("userName",response.data.username);
                    location.href = '/index.html';
                    // history.go(-1);
                }else if(response.code == 100 || response.code == 201){
                    $("#login-error").css("display","block");
                    $("#login-error").html(response.msg);
                }
            },
            error:function() {
                alert("系统繁忙，请稍后再试...");
            }
        });
    }
    $('#logSubmit').click(function () {
        login();
    });
    //enter登陆
    $('#logPassword').bind('keypress', function (e) {
        if(e.keyCode == "13"){
            login();
        }
    });
});